1 The basics

1.1 Rendering R Markdown documents

R Markdown makes it easy to turn a document of notes into different output formats including presentations.

1.2 For example …

… I might start to collect some notes on “Presentations with R Markdown” in a simple R Markdown document.

I want to include some references and start with a simple document with the following YAML header:

1.3 Controlling output with YAML

---
title: "Presentations with R Markdown"
subtitle: "Some examples"
author: Stefan Daume
date: "2024-04-29"
output: 
  bookdown::html_document2:
    theme: paper
always_allow_html: true
bibliography: references.bib
link-citations: no
---

Using knitr (e.g. the “Knit” button in RStudio) renders this document as an HTML page.

1.4 R Markdown as an HTML page

Which would look like that:

1.5 R Markdown

As with any R Markdown document embedded R code chunks will be evaluated and included in the rendered document. For example:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

1.6 Including Plots

Or a plot:

plot(pressure)

1.7 R Markdown book

Consult the R Markdown book (Xie, Allaire, and Grolemund 2023) for more options.

Including this citation demonstrates how dynamic references and bibliographies can be included in any R Markdown output format. Check the “References” section at the end of the document.

2 Move to presentation format

2.1 Change the output format

By changing the output format in the YAML header we can turn the initial document into a presentation.

---
title: "Presentations with R Markdown"
subtitle: "Some examples"
author: Stefan Daume
date: "2024-04-29"
output:
  ioslides_presentation:
    widescreen: true
always_allow_html: true
bibliography: references.bib
link-citations: no
---

ioslides is only one of several supported HTML presentation formats.

2.2 Structuring the presentation

In most supported HTML presentation formats slides headers of type # and ## are translated in individual slides with the header text as slide title.

Using --- creates a slide without a title.

2.3 Useful features

Most HTML presentation output formats support useful features like presenter mode out of the box. This presentation in presenter mode:

https://sdaume.github.io/srccoders/rmarkdown_presentations.html?presentme=true

Check the R Markdown book (Xie, Allaire, and Grolemund 2023) for more features such as incremental display of content, custom CSS, templates etc.

This is my note.

  • It can contain markdown
  • like this list

2.4 Online presentations

The generated HTML presentation (or any HTML document) can be hosted online via GitHub pages.

This presentation is at: https://sdaume.github.io/srccoders/rmarkdown_presentations.html

3 Document conversion with pandoc

3.1 A more involved approach

The ‘heavy lifting’ of document transformations from R Markdown is enabled with pandoc (https://pandoc.org/).

Using pandoc may offer useful additional options when converting documents.

An alternative approach to creating presentations from R Markdown and using pandoc directly is documented here: https://github.com/sdaume/rmarkdown-presentation-template (slightly outdated now)

3.2 R Markdown, pandoc, reveal.js

The referenced example creates a HTML presentation based on the reveal.js framework, starting with R Markdown it uses pandoc to create presentations like this.

It is versatile, offers different plugins and makes it possible to include advanced visualizations such as this

4 The end

4.1 Code examples

The Rmd file for this presentation is here: https://github.com/sdaume/srccoders

References

Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2023. R Markdown: The Definitive Guide.